<template>
  <div class="page">
    <div class="layui-fluid">
      <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
          <div class="layui-card">
            <div class="layui-card-body">
              <div class="layui-form" lay-filter="">
                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">等级名称</label>
                    <div class="layui-input-inline">
                      <input type="text" name="name" placeholder="请输入等级名称" v-model="itemData.name" autocomplete="off"
                        class="layui-input" />
                    </div>
                  </div>
                </div>

                <div class="layui-form-item">
                  <label class="layui-form-label">会员等级</label>
                  <div class="layui-input-inline">
                    <select name="memberGrade" lay-filter="memberGrade" v-model="itemData.memberGrade">
                      <option value="ZERO">非会员</option>
                      <option value="ONE">1级</option>
                      <option value="TWO">2级</option>
                      <option value="THREE">3级</option>
                      <option value="FOUR">4级</option>
                      <option value="FIVE">5级</option>
                      <option value="SIX">6级</option>
                      <option value="SEVEN">7级</option>
                      <option value="EIGHT">8级</option>
                      <option value="NINE">9级</option>
                      <option value="TEN">10级</option>
                      <option value="ELEVEN">11级</option>
                      <option value="TWELVE">12级</option>
                      <option value="THIRTEEN">13级</option>
                      <option value="FOURTEEN">14级</option>
                      <option value="FIFTEEN">15级</option>
                    </select>
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">会员价格</label>
                    <div class="layui-input-inline">
                      <input type="number" name="price" placeholder="单位(元)" v-model="itemData.price" autocomplete="off"
                        class="layui-input" />
                    </div>
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">折扣</label>
                    <div class="layui-input-inline">
                      <input type="number" name="discount" placeholder="75表示7.5折" autocomplete="off"
                        v-model="itemData.discount" class="layui-input" />
                    </div>
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit @click="sure">
                      确认
                    </button>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "memberset",
  data () {
    return {
      id: "",
      itemData: {
        name: "", //等级名称
        memberGrade: "", //会员等级
        price: "", //会员价格
        discount: "",//折扣

      },
      type: localStorage.getItem("type")
    };
  },
  mounted () {
    var vm = this;
    window.getdates = this.getdates;
  },
  methods: {
    getdates: function (data) {
      var vm = this;
      this.id = data.id;
      if (vm.type == "1") {
        var url = "/shop/aapi/v1.9/levels/" + data.id;
      } else {
        var url = "/shop/bapi/v1.9/levels/" + data.id;
      }
      ajaxRequest(url, "GET", "json", "", function (ret, err) {
        vm.itemData = ret.data;
      });
    },
    sure: function () {
      var vm = this;

      var tid = "POST";
      var dates = this.itemData;
      if (this.id) {
        dates.id = this.id;
        tid = "PUT";
      }
      // alert(JSON.stringify(dates))
      var url = "/shop/aapi/v1.9/levels/";

      ajaxRequest(url, tid, "json", dates, function (ret, err) {
        layer.msg("操作成功");
        setTimeout(function () {
          var index = parent.layer.getFrameIndex(window.name);
          parent.layer.close(index);
          parent.location.reload();
        }, 1000);
      });
    }
  },
  updated: function () {
    var vm = this;
    layui.use("form", function () {
      var form = layui.form;
      form.render();
      form.on("select(memberGrade)", function (data) {
        vm.itemData.memberGrade = data.value;
      });
    });
  }
};
</script>
<style scoped></style>
